package cn.liberals.system.controller;

import cn.liberals.basic.utils.AjaxResult;
import cn.liberals.basic.utils.PageList;
import cn.liberals.system.domain.Dictionarytype;
import cn.liberals.system.query.DictionarytypeQuery;
import cn.liberals.system.service.IDictionarytypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Description: 部门的接口类
* @Author: Mr.She
* @Version: 1.0
* @Date:  2022/6/24 10:10
*/
@RestController
@RequestMapping("/dictionarytype")
@Api(value = "部门的API",description="部门相关的CRUD功能")
public class DictionarytypeController {

    @Autowired
    private IDictionarytypeService dictionarytypeService;

   /* 
   * @Title: loadById
   * @Description: 通过ID查询
   * @Author: liberals
   * @Version: 1.0
   * @Date:  2022/6/26 15:22  
   * @Parameters: 
   * @Return 
   */
    @GetMapping("/{id}") // 请求地址：http://localhost:8080/dictionarytype/1 GET请求
    @ApiOperation(value = "通过ID查询" )
    public Dictionarytype loadById(@ApiParam(value="部门表的主键",required = true) @PathVariable("id") Long id){
        return dictionarytypeService.loadById(id);
    }

    /**
    * @Title: loadAll
    * @Description: 查找所有
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:23  
    * @Parameters: 
    * @Return 
    */
    @GetMapping// 请求地址：http://localhost:8080/dictionarytype GET请求
    public List<Dictionarytype> loadAll(){
        return dictionarytypeService.loadAll();
    }

    /*
    * @Title: remove
    * @Description: 删除
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:26
    * @Parameters:
    * @Return
    */
    @DeleteMapping("/{id}") // 请求地址：http://localhost:8080/dictionarytype/1 GET请求
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            dictionarytypeService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }


    /*
    * @Title: addOrUpt
    * @Description: 新增或修改
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:26
    * @Parameters:
    * @Return
    */
    @PutMapping
    public AjaxResult addOrUpt(@RequestBody Dictionarytype dictionarytype){
        try {
            if(dictionarytype.getId() == null){
                dictionarytypeService.save(dictionarytype);
            }else {
                dictionarytypeService.update(dictionarytype);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }


    /*
    * @Title: queryData
    * @Description: 查找负责人
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:24
    * @Parameters:
    * @Return
    */
    @PostMapping
    public PageList<Dictionarytype> queryData(@RequestBody DictionarytypeQuery dictionarytypeQuery){
        PageList<Dictionarytype> data = dictionarytypeService.queryData(dictionarytypeQuery);
        return data;
    }


    /*
    * @Title: batchDel
    * @Description: 批量删除
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:26
    * @Parameters:
    * @Return
    */
    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        try {
            dictionarytypeService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }

}
